﻿using System;
using Fibonacci;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication
{

    public class Program
    {



        public static void Main(string[] args)
        {
            /*
            Console.WriteLine("Hello World!");

            Console.WriteLine("Fibonacci Numbers 1-15:");

            for (int i = 0; i < 15; i++)
            {
                Console.WriteLine($"{i+1}: {FibonacciHelper.FibonacciNumber(i)}");
            }
            */

            /*
            Console.WriteLine("主线程开始！");

            //创建前台工作线程
            Thread t1 = new Thread(Task1);
            t1.Start();

            //创建后台工作线程
            Thread t2 = new Thread(new ParameterizedThreadStart(Task2));
            t2.IsBackground = true;//设置为后台线程
            t2.Start("传参");

            Console.ReadLine();
            */


            Console.WriteLine("主线程开始！");
            //创建要执行的任务
            WaitCallback workItem = state => Console.WriteLine("当前线程Id为：" + Thread.CurrentThread.ManagedThreadId);

            //重复调用10次
            for (int i = 0; i < 10; i++)
            {
                ThreadPool.QueueUserWorkItem(workItem);
            }
            Console.ReadLine();
        }


        private static void Task1()
        {
            Thread.Sleep(1000);//模拟耗时操作，睡眠1s
            Console.WriteLine("前台线程被调用！");
        }

        private static void Task2(object data)
        {
            Thread.Sleep(2000);//模拟耗时操作，睡眠2s
            Console.WriteLine("后台线程被调用！" + data);
        }
    }
}
